package com.gitee.base.mybatis;

import com.gitee.base.modules.BaseController;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MybatisMetaObjectHandler extends BaseController implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.fillStrategy(metaObject,"cid", getLoginUserId());
        this.fillStrategy(metaObject,"ctime", LocalDateTime.now());
        this.fillStrategy(metaObject,"uid", getLoginUserId());
        this.fillStrategy(metaObject,"utime", LocalDateTime.now());
        this.fillStrategy(metaObject,"userId", getLoginUserId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.fillStrategy(metaObject,"uid", getLoginUserId());
        this.fillStrategy(metaObject,"utime", LocalDateTime.now());
    }
}
